package com.happy.mvcframe.base;

import android.app.Application;

import com.google.gson.Gson;
import com.happy.mvcframe.R;
import com.scwang.smartrefresh.header.WaterDropHeader;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.footer.BallPulseFooter;

import me.jessyan.autosize.AutoSizeConfig;
import me.jessyan.autosize.unit.Subunits;


public class BaseApp extends Application {
    //初始化context对象
    private static BaseApp context;

    @Override
    public void onCreate() {
        super.onCreate();
        context = this;
        //屏幕适配 开启支持 Fragment 自定义参数的功能
        initConfig();
        //初始化SmartRefreshLayout
        initSmartRefreshHeadAndFoot();
        //初始化极光
//        JPushInterface.setDebugMode(true);
//        JPushInterface.init(this);
    }

    private void initSmartRefreshHeadAndFoot() {
        //设置全局的Header构建器
        SmartRefreshLayout.setDefaultRefreshHeaderCreator(((contexts, layout) -> {
            layout.setPrimaryColorsId(R.color.colorPrimaryDark,R.color.colorAccent,R.color.colorPrimary);//全局设置主题颜色
            return new WaterDropHeader(this);
        }));
        //设置全局的Footer构建器
        SmartRefreshLayout.setDefaultRefreshFooterCreator((contexts, layout) -> {
            //指定为经典Footer，默认是 BallPulseFooter
            return new BallPulseFooter(this);
        });
    }

    private void initConfig() {
        AutoSizeConfig.getInstance()
                .setCustomFragment(true)
                .getUnitsManager()
                .setSupportDP(true)
                .setSupportSP(true)
                .setSupportSubunits(Subunits.MM);
    }

    public static BaseApp getContext() {
        return context;
    }
}
